﻿#include "videocontroller.h"

#include <QDebug>

VideoController::VideoController(JsonConfig* jsonConfig, QObject *parent) : QObject(parent), m_jsonConfig(jsonConfig)
{  
    // 初始化
    init();
}

void VideoController::setServoMachineList(const QStringList &servoMachineList)
{
    m_servoMachineList.clear();
    m_servoMachineList.append(servoMachineList);
}

bool VideoController::getVideoPlayback(const QString &video, VideoPlayback &playback)
{
    bool ret = false;

    int size = m_servoMachineList.size();
    switch (size) {
    case 1:
        if (m_onePlaybackMap.contains(video)) {
             playback.startTime = m_onePlaybackMap.value(video).startTime;
             playback.duration = m_onePlaybackMap.value(video).duration;
             ret = true;
        }
        break;
    case 2:
        if (m_twoPlaybackMap.contains(video)) {
             playback.startTime = m_twoPlaybackMap.value(video).startTime;
             playback.duration = m_twoPlaybackMap.value(video).duration;
             ret = true;
        }
        break;
    case 3:
        if (m_threePlaybackMap.contains(video)) {
             playback.startTime = m_threePlaybackMap.value(video).startTime;
             playback.duration = m_threePlaybackMap.value(video).duration;
             ret = true;
        }
        break;
    case 4:
        if (m_fourPlaybackMap.contains(video)) {
             playback.startTime = m_fourPlaybackMap.value(video).startTime;
             playback.duration = m_fourPlaybackMap.value(video).duration;
             ret = true;
        }
        break;
    default:
        break;
    }

    return ret;
}

void VideoController::init()
{
    /*
     * 1级: 1_CJTD, 1_JX, 1_WZ11, 1_ZT8, 1_JPL1_2, 1_JPL1_15, 1_JPL1_30, 1_JPL1_60, 1_JPL1_70, 1_JPL1_80, 1_JPL1_100, 1_JPL1_130, 1_JPL1_150, 1_JPL2_2, 1_JPL2_6.28, 1_WZ11, 1_ZLGZ11_1, 1_ZLGZ11_2, 1_ZLGZ11_3
     * 2级: 2_CJTD, 2_JX, 2_WZ70, 2_ZT52, 2_JPL2_2, 2_JPL2_30, 2_JPL2_50, 2_JPL2_60, 2_JPL2_70, 2_JPL2_100, 2_JPL2_110, 2_JPL2_120, 2_JPL2_150, 2_JPL4_6.28, 2_JPL4_20, 2_JPL4_60, 2_WZ70, 2_ZLGZ70_1, 2_ZLGZ70_2, 2_ZLGZ70_3
     */

    // 1, 2, 3, 4个伺服机构
    m_onePlaybackMap = m_jsonConfig->playbackMap("one");
    m_twoPlaybackMap = m_jsonConfig->playbackMap("two");
    m_threePlaybackMap = m_jsonConfig->playbackMap("three");
    m_fourPlaybackMap = m_jsonConfig->playbackMap("four");

    //QMapIterator<QString, VideoPlayback> iter(m_onePlaybackMap);
    //while (iter.hasNext()) {
    //    iter.next();
    //    qDebug() << iter.key() << ": " << iter.value().startTime << ", " << iter.value().duration;
    //}
}
